﻿Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class PermissionsServices
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function listOwnedGames(ByVal ParticipantID As Integer) As String
        'list of games this user owns
        Dim sql As String
        sql = "SELECT Game.GameID, Game.GameName FROM GameParticipant INNER JOIN Game ON GameParticipant.GameID = Game.GameID WHERE GameParticipant.GroupID = 1 AND GameParticipant.ParticipantID ='" & ParticipantID & "'"

        Return True

    End Function

    <WebMethod()> _
    Public Function listCurrentParticipants(ByVal gameID As Integer) As String
        'this function will do inner join on game_ID in Game_Participant table and the Game Table and display list of users in game
        Dim sql As String
        sql = "SELECT Participant.LastName, Participant.FirstName FROM Participant INNER JOIN GameParticipant ON Participant.ParticipantID = GameParticipant.ParticipantID WHERE GameParticipant.GameID = '" & gameID & "'"

        Return True

    End Function

    <WebMethod()> _
    Public Function listAvailableParticipants(ByVal gameID As Integer) As String
        'This function needs to return the list of participants excluding the participants returned listCurrentParticipants function
        Dim sql As String
        'sql = "SELECT Distinct ParticpantID FROM ((SELECT last name of all participants) UNION ALL (Select last name of current game participants))"
        'sql = "((SELECT LastName FROM Participant) UNION ALL (SELECT Participant.LastName FROM Participant INNER JOIN GameParticipant ON Participant.ParticipantID = GameParticipant.ParticipantID WHERE NOT GameParticipant.GameID = '" & gameID & "'))"
        sql = "SELECT LastName FROM Participant WHERE LastName NOT IN (SELECT Participant.LastName FROM Participant INNER JOIN GameParticipant ON Participant.ParticipantID = GameParticipant.ParticipantID WHERE GameParticipant.GameID = '" & gameID & "')"

        Return True
    End Function

End Class